package com.example.viewmodel;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class AutoAddActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tv_add;
    private MyViewModel viewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auto_add);

        tv_add = findViewById(R.id.tv_add);
        findViewById(R.id.btn_add).setOnClickListener(this);
        viewModel = new ViewModelProvider(this, new ViewModelProvider.AndroidViewModelFactory(getApplication())).get(MyViewModel.class);
        tv_add.setText(String.valueOf(viewModel.textAdd));
    }

    @Override
    public void onClick(View view) {
        tv_add.setText(String.valueOf(++viewModel.textAdd));
    }
}